package com.burgeon.backend.Controller;

import com.burgeon.backend.entity.Coupon;

import com.burgeon.backend.entity.Reviews;
import com.burgeon.backend.entity.Template;
import com.burgeon.backend.entity.TemplateRecord;
import com.burgeon.backend.service.MessageTemplateService;
import com.burgeon.backend.stsutil.ResponseResult;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("messageTemplate")
public class MessageTemplateController extends BaseController {
    @Autowired
    MessageTemplateService messageTemplateService;

    @RequestMapping("repetition")
    public ResponseResult<Void> Repetition(String rcode, String account) {
        messageTemplateService.ReviewsExist(rcode, account);
        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("reviews")
    public ResponseResult<Void> CreateReviews(Reviews reviews, String account) {
        messageTemplateService.CreateConsumptionBos(reviews, account);
        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("item")
    public ResponseResult<Coupon> GetItem(String account, String code) {
        if (account == null && code == null) {
            return null;
        }
        Coupon data = messageTemplateService.GenCouponItem(account, code);
        return new ResponseResult<Coupon>(SUCCESS, data);
    }

    @RequestMapping("getid")
    public ResponseResult<Template> GetId(String account) {
        //String account = session.getAttribute("account").toString();
        Template data = messageTemplateService.GetTemplate(account);
        return new ResponseResult<Template>(SUCCESS, data);
    }

    @RequestMapping("updata")
    public ResponseResult<Void> UpData(Template template, String account) {
        //String account = session.getAttribute("account").toString();
        template.setAccount(account);
        messageTemplateService.UpDataTemplate(template);
        return new ResponseResult<>(SUCCESS);
    }

    //查询模板消息列表
    /*account 必传
    * 手机号：phone
    * 模板类型flag：A:购物券 B：消费提醒 C:充值提醒 D:消费评价 E：新会员送积分 F：推荐新会员送积分
    * 日期查询：startTime:开始时间 endTime:结束时间
    * */
    @RequestMapping("findMessageRecord")
    public ResponseResult<List<TemplateRecord>> findMessageRecord(String account,String phone,String flag,String startTime,String endTime){
        List<TemplateRecord> data = messageTemplateService.findMessageRecord(account,phone,flag,startTime,endTime);
        return new ResponseResult<List<TemplateRecord>>(SUCCESS,data);
    }

}
